package com.kds.changzhou.utility;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import java.io.StringReader;

/**
 * @author 孔德嵩
 * @date 2023-11-07 10:58
 * @copyright Copyright (c) 2023 Dell
 */
@Component
@Slf4j
public class XmlParserService {

    @Autowired
    private DocumentBuilder documentBuilder;

    public Document parseXml(String xmlString) {
        try {

            return documentBuilder.parse(new InputSource(new StringReader(xmlString)));
        } catch (Exception e) {
            throw new RuntimeException("Failed to parse XML", e);
        }
    }
}
